<template>
  <view>
    <my-address></my-address>
    <view class="cartTitle">
      <uni-icons  type="shop" size="18"></uni-icons>
      <text class="cart-title-text">购物车</text>
    </view>
    <uni-swipe-action>
       <block v-for="(cartItem,i) in cart" :key="i">
      <uni-swipe-action-item :right-options="options" @click="swipeDelete(cartItem)">
        <my-goods :goods="cartItem" :showRadio="true" @radioChange="radioChangeHandler" :showNum="true" @numChange="numChange"></my-goods>
        </uni-swipe-action-item>
         </block>
    </uni-swipe-action>
    <my-settle></my-settle>
  </view>
</template>

<script>
// 导入自己封装的 mixin 模块
import badgeMix from '@/mixins/tabbar-badge.js'
import { mapState,mapMutations,mapGetters} from 'vuex'
import cart from '../../store/cart';
export default {
  // 将 badgeMix 混入到当前的页面中进行使用
  mixins: [badgeMix],
    data() {
      return {
        options:[{
          text:'删除',
          style:{
            backgroundColor:"#C00000"
          }
        }]
      };
    },
    computed:{
      ...mapState('m_cart',['cart']),
      
    },
    methods:{
      ...mapMutations('m_cart',['updateCart','updateCartCount','swipeDel']),
      radioChangeHandler(e){
        this.updateCart(e)
      },
      numChange(e){
       this.updateCartCount(e)
      },
      swipeDelete(cartItem){
   uni.showModal({
   	title: '是否确认删除',
   	success:  (res)=> {
   		if (res.confirm) {
   		this.swipeDel(cartItem.goods_id)
   		uni.showToast({
   			title: '删除成功',
   		});
   		} else if (res.cancel) {
   			
   		}
   	}
   });
    
      }
    }
  }
</script>

<style lang="scss">
.cartTitle{
  .cart-title-text{
    margin-left: 10px;
  }
}
</style>
